from bs4 import BeautifulSoup
import requests
import re

#萌娘百科经常打不开，不要怕，这是正常的。
url = 'http://zh.moegirl.org.cn/Mainpage'

response = requests.get(url)
soup = BeautifulSoup(response.text, 'lxml')

data0 = soup.select(
    '#mainpage-a > div.mainpage-newsbox > div.mainpage-1stcontent > p:nth-child(2)')

fo = open("C:\\Users\\metasequoia\\Desktop\\文档\\爬虫\\foo.txt", "w+")
for x in data0:
    fo.write(x.get_text()+"\n")
fo.close()

with open("C:\\Users\\metasequoia\\Desktop\\文档\\爬虫\\foo.txt", "r") as f:  # 打开文件
    data = f.read()  # 读取文件

sentences = re.split(r"([。！？])", data)
sentences.append("")
sentences = ["".join(i) for i in zip(sentences[0::2], sentences[1::2])]
print(sentences)

fo = open("C:\\Users\\metasequoia\\Desktop\\文档\\爬虫\\foo.txt", "w+")
for x in sentences:
    fo.write(x+"\n")
fo.close()
